<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>

<body>
    <div id="box">
        <kerwin-navbar></kerwin-navbar><br>
       <kerwin-tabbar></kerwin-tabbar>

    </div>

    <script type="text/javascript">
        //创建并封装全局组件
        Vue.component("kerwin-navbar", {
            //采用模板字符串引入样式
            template: `
        <div style="background:yellow;">
            <button @click="handleBack()">返回</button>
            <span>导航栏---{{myname}}</span>
            <button @click="handleHome()">首页</button>

            <child>></child>
        </div> 
            `,//模板
            methods: {
                handleBack() {
                    console.log('返回')
                },
                handleHome() {
                    console.log('homeclick')
                },
            },
            computed: {

            },
            watch: {

            },
            data(){         // data 必须写成函数
                return {
                    myname:"child-name"
                }
            }
        })

        //创建全局组件
        Vue.component("kerwin-tabbar", {
            template:`
            <div style="background:red;">
                tabbar
                <child>></child>
                <tabbarchild></tabbarchild>
            </div>
            `,
            components:{
                "tabbarchild":{
                    //局部定义组件，只有kerwin-tabbar组件可以使用
                    template:`<div>tabbarchild</div>`
                }
            }
        })

        //定义孩子组件
        Vue.component("child", {
            template:`
           <div>child</div>
            `
        })

        // 根组件
        new Vue({
            el: "#box",
            data: {
                myname: "kerwin"
            }
        })
    </script>
</body>

</html>